//
//  DYZEffectDateController.m
//  发布寻车
//
//  Created by xmy on 16/8/19.
//  Copyright © 2016年 xmy. All rights reserved.
//

#import "DYZEffectDateController.h"
#import "UIColor+Addition.h"
#import "DYZRandomColorController.h"
#import "UILabel+Addition.h"

static NSString *cellid = @"cellid";
@interface DYZEffectDateController ()<UITableViewDelegate,UITableViewDataSource>

@property(nonatomic,strong)NSArray *loadData;
@property(weak,nonatomic)UITableView *tableView;

@end

@implementation DYZEffectDateController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    
    [self setupUI];
    [self addChoose];
    
   self.loadData = [self loadData];
   self.navigationItem.title = @"有效期";
   self.tableView.tableFooterView = [[UIView alloc]initWithFrame:CGRectZero];
}

- (void)setupUI{
    UITableView *tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height - 50) style:UITableViewStylePlain];
    
    [self.view addSubview:tableView];
    
    tableView.dataSource = self;
    tableView.delegate = self;
    
    self.tableView = tableView;
    //注册
    [tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:cellid];
    
}

//添加自定义view
- (void)addChoose{
    
    UIView *addView = [[UIView alloc]init];
    addView.userInteractionEnabled = YES;
    
    //背景图片
    UIImageView *backImage = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"more2"]];
    backImage.bounds = addView.frame;
    [addView addSubview:backImage];
    
    UILabel *label = [UILabel labelWithText:@"自定义区域" andTextColor:[UIColor whiteColor] andFontSize:14];
    [label sizeToFit];
    [addView addSubview:label];
    
    UIImageView *imageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"arrow2"]];
    
    [addView addSubview:imageView];
    [imageView sizeToFit];
    
    [self.view addSubview:addView];
    
    
    //添加手势
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapGesture:)];
    
    [addView addGestureRecognizer:tap];
    
    [addView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.left.right.equalTo(self.view);
        make.height.offset(50);
    }];
    [backImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(addView);
    }];
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(10);
        make.top.bottom.equalTo(addView);
    }];
    [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.offset(-10);
        make.centerY.equalTo(addView);
    }];
    
    
}
//手势事件
- (void)tapGesture:(UITapGestureRecognizer *)tap{
    
    DYZRandomColorController *vc = [[DYZRandomColorController alloc]init];
    
    vc.flag = 3;
    
    [self.navigationController pushViewController:vc animated:YES];
    
}

- (NSArray *)loadData{
    
    NSString *path = [[NSBundle mainBundle] pathForResource:@"date.plist" ofType:nil];
    
    NSArray *array = [NSArray arrayWithContentsOfFile:path];
    
    return array;
}


#pragma mark - Table view data source

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

   return self.loadData.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellid forIndexPath:indexPath];
    
    cell.textLabel.text = self.loadData[indexPath.row];
    cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
    cell.textLabel.font = [UIFont systemFontOfSize:14];
    [cell.textLabel setTextColor:[UIColor colorWithHex:0x333333]];

    return cell;
}
//cell的点击事件
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    //取消点击效果
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
}

@end
